home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 39 < prev    next >
Text File  |  1996-08-06  |  2KB  |  61 lines

  1. Path: qcd.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Undefined result vs. int's holding undefined values.
  5. Date: 6 Jan 1996 00:11:48 GMT
  6. Organization: Los Alamos National Laboratory
  7. Distribution: world
  8. Message-ID: <4ckeo4$sf5@newshost.lanl.gov>
  9. References: <4ck70b$rd7@news.informix.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11.  
  12. In article <4ck70b$rd7@news.informix.com>, Daniel Wood <dwood> writes:
  13. |> THE TEST CASE, on SCO:
  14. |> 
  15. |> main() { f(-2147483647, 1879048192); }
  16. |> 
  17. |> f(int x, int y) {
  18. |>     int r;
  19. |> 
  20. |>     if ((r=(x-y)) > 0)
  21. |>         printf("1: r greater than 0\n");
  22. |> 
  23. |>     if (r > 0)
  24. |>         printf("2: r greater than 0\n");
  25. |> }
  26. |> 
  27. |> On SCO only the second print occurs.  The reason given to me is that ANSI
  28. |> states
  29. |> that the result of an overflowing/underflowing operation is undefined.  The
  30. |> implementation is free to do what it wants with the result.  This is fine
  31. <snip>
  32. |> Saying a result is undefined "IS NOT EQUAL TO" saying that a C int
  33. variable 
  34. |> can actually hold an undefined value.  If you think the test case is
  35. running 
  36. |> acceptably, as described above, then tell me the section of the standard
  37. that 
  38. |> states or implies that an int variable can hold an undefined value.
  39. |> 
  40. |> Why say ye all?
  41.  
  42. 3.14 defines `undefined behaviour' as `behaviour, upon use of nonportable or
  43. erroneous program construct, of errnoeous data, or of indeterminately valued
  44. objects, for which this International Standard imposes no requirements.' Note
  45. that the entire _behaviour_ is undefined if erroneous data or an
  46. indeterminately valued object is used. So, a compiler is within rights to do
  47. whatever it sees fit, because it is not bound by any `requirements' of the
  48. standard including, inter alia, the requirement that the value of a variable
  49. not change arbitrarily; or that the controlled statement in an if be executed
  50. if the control expressions evaluates unequal to 0.
  51.  
  52. Cheers
  53. Tanmoy
  54. -- 
  55. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  56. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  57. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  58. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  59. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  60. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  61.